package org.example.rmsmsapi.service.impl;


import lombok.Data;
import org.example.rmsmsapi.Utils.DateUtils;
import org.example.rmsmsapi.config.DS;
import org.example.rmsmsapi.model.suser;
import org.example.rmsmsapi.model.uRoles;
import org.example.rmsmsapi.sdao.smapper;
import org.example.rmsmsapi.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

@Service
public class UserServiceImpl implements UserService {


    @Resource
    private smapper apper;
    @Override
    @DS("datasurce1")
    public uRoles validateUser(String userName, String password) {
        suser s1=new suser();
        s1=apper.GetUserByUserCode(userName);


        // 查询用户
       // User user = userMapper.selectByUserName(userName);
        if (s1== null) {
            return null;
        }

        // 验证密码（明文比较，实际项目中应使用加密方式）
        if (!password.equals(s1.getPassword())) {
            return null;
        }
        ArrayList<String> r=new ArrayList<>();
        r=apper.GetPermes(s1.getRoleid());
        uRoles u=new uRoles();
        u.setRoles(r);
        u.setRoleid(s1.getRoleid());
        u.setUserCode(s1.getUserCode());
        u.setCreateTime(s1.getCreateTime());
        u.setStop(s1.getStop());
        u.setHosId(s1.getHosId());
        //u.setLoginTime(s1.getLoginTime());
        u.setUserName(s1.getUserName());
        u.setUserId(s1.getUserId());
        u.setUserType(s1.getUserType());
        //u.setToken(s1.getToken());
        u.setAvatar(s1.getAvatar());
        u.setIntroduction(s1.getIntroduction());
        String date;
        date= DateUtils. Getdnowdatexx();
        apper.uPuser(s1.getUserId(), date);
        u.setLoginTime(date);

        // 验证用户状态
//        if (user.getStatus()!=null && user.getStatus()!=1) {
//            return null;
//        }

        return u;
    }
}    